*This is a file that generate a small example of commodity flow problem

Options seed = 200, optcr = 0, mip = cplex;

Sets
	K commodity /k1 * k2 /
	N nodes     /n1 * n5 /
	NI(N)
	NJ(N)
	alias (N,M)
;
Sets A(N, M) archs;

NI(N) = yes;
NJ(M) = yes;
A(N,M)$(uniform(0,1) >= 0.2) = yes

Parameters
	c(N, M, K)   unit flow cost for arc ij
	d(N, M)     Arch capacity
	q(K)     quantify for K the commodity
	b(N,K)   source(+1) dest(-1) indicator
	/n1.k1 = 1,
	 n3.k1 =-1,
	 n2.k2 = 1,
	 n4.k2 = -1/
;

*Generate random numbers for c, d, b
c(A, K)      = uniform(0, 1);
d(A)         = uniform(0, card(K));
q(K)         = uniform(0, 1);

Variables
	x(N, M, K)
	z
;
Binary variable x;

Equations
	cost     total cost 
	cc(N, M) capacity constraint
	fc(N, K) flow constraint;
cost..       z =e= sum( (A, K), c(A, K) * q(K) * x(A, K));
cc(A)..      sum( K, q(K) * x(A, K) ) =l= d(A);
fc(N, K)..   sum( NJ$A(N, NJ), x( N, NJ, K) ) - sum( NI$A(NI,N), x(NI, N, K) )
	     =e= b(N, K);

Model Flow /cost, cc, fc/;
Solve Flow using mip minimizing z;

display N, K, A;
display b, c, d, q; 
display z.L, x.L;	
	
